package com.irdstudio.efp.esb.api.rest.zzd;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSONObject;
import com.irdstudio.efp.esb.api.bean.zzd.ReqRepayConfirmBean;
import com.irdstudio.efp.esb.api.rest.EsbServerController;
import com.irdstudio.basic.framework.core.exception.ESBException;
import com.irdstudio.basic.framework.core.util.InterfaceCheckUtils;

/**
 * 用户还款确认接口controller
 * @author qiuyf
 * @since 2018年12月18日 下午9:34:40
 * @version 1.0
 */
public class RepayConfirmController implements EsbServerController {


	/**
	 * 日志记录变量
	 */
	private static Logger logger = LoggerFactory.getLogger(RepayConfirmController.class);

	@Override
	public String execute(String esbReqBodyBean) throws ESBException, Exception {
		String esbRespBodyBean = null;
		try {
			// 1.将请求报文对象转成相应的json
			ReqRepayConfirmBean reqRepayConfirmBean = JSONObject.parseObject(esbReqBodyBean, ReqRepayConfirmBean.class);

			// 2.必输项校验
			this.checkRequired(reqRepayConfirmBean);

			// 3.调用对应中台服务处理 TODO

			// 4.判断查询结果 TODO


			// 5.封装返回报文 TODO

			logger.info("");
			throw new ESBException();
		} catch (ESBException e) {
			logger.error("调用用户还款确认接口出错，错误信息为："+e.getMessage());
		} catch (Exception e) {
			logger.error("调用用户还款确认接口出错，错误信息为："+e.getMessage());
		}

		return esbRespBodyBean;
	}

	/**
	 * 校验还款确认接口请求报文的必输项
	 * @param reqRepayConfirmBean 还款确认接口请求报文bean
	 * @author qiuyf
	 * @since 2018年12月19日 上午9:06:05
	 * @version 1.0
	 * @throws Exception 
	 */
	private void checkRequired(ReqRepayConfirmBean reqRepayConfirmBean) throws Exception {
		//协议参数
		InterfaceCheckUtils.getValue("signType", "签名方式", reqRepayConfirmBean.getSignType(), true);
		InterfaceCheckUtils.getValue("serviceVersion", "接口版本", reqRepayConfirmBean.getServiceVersion(), true);
		InterfaceCheckUtils.getValue("inputCharset", "字符集", reqRepayConfirmBean.getInputCharset(), true);
		InterfaceCheckUtils.getValue("sign", "签名", reqRepayConfirmBean.getSign(), true);
		InterfaceCheckUtils.getValue("signKeyIndex", "密钥序号", reqRepayConfirmBean.getSignKeyIndex(), true);
		//业务参数校验
		InterfaceCheckUtils.getValue("productCorpSpid", "基金公司商户号", reqRepayConfirmBean.getProductCorpSpid(), true);
		InterfaceCheckUtils.getValue("userId", "真身id", reqRepayConfirmBean.getUserId(), true);
		InterfaceCheckUtils.getValue("applSeq", "贷款订单号", reqRepayConfirmBean.getApplSeq(), true);
		InterfaceCheckUtils.getValue("loanAmt", "贷款本金", reqRepayConfirmBean.getLoanAmt(), true);
		InterfaceCheckUtils.getValue("curType", "币种", reqRepayConfirmBean.getCurType(), true);
		InterfaceCheckUtils.getValue("repayApplSeq", "还款订单号", reqRepayConfirmBean.getRepayApplSeq(), true);
		InterfaceCheckUtils.getValue("loanTime", "贷款时间", reqRepayConfirmBean.getLoanTime(), true);
		InterfaceCheckUtils.getValue("repayTime", "还款时间", reqRepayConfirmBean.getRepayTime(), true);
		InterfaceCheckUtils.getValue("repayAmt", "还款金额", reqRepayConfirmBean.getRepayAmt(), true);
		InterfaceCheckUtils.getValue("repayPrcpAmt", "还款本金金额", reqRepayConfirmBean.getRepayPrcpAmt(), true);
		InterfaceCheckUtils.getValue("repayIntAmt", "还款利息金额", reqRepayConfirmBean.getRepayIntAmt(), true);
		InterfaceCheckUtils.getValue("stampDuty", "印花税", reqRepayConfirmBean.getStampDuty(), true);
		InterfaceCheckUtils.getValue("repayOdInt", "还款罚息", reqRepayConfirmBean.getRepayOdInt(), true);
		InterfaceCheckUtils.getValue("repayType", "还款类型", reqRepayConfirmBean.getRepayType(), true);
		InterfaceCheckUtils.getValue("explain", "还款说明", reqRepayConfirmBean.getExplain(), true);
	}


}
